package com.tzxscu.hosdrool.drools;

import com.tzxscu.hosdrool.models.BillItems;
import com.tzxscu.hosdrool.models.BillItemsBean;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;


public class droolsapi_2 {
    private static Logger logger = LoggerFactory.getLogger(droolsapi_2.class);
    private static List<BillItemsBean> listbill = new ArrayList<>();
    public static String drools(List<BillItems> billItems){
        try {
            logger.info("输入---------------------------------------------------------");
            logger.info(billItems.toString());
            KieServices ks = KieServices.Factory.get();
            KieContainer kieContainer = ks.getKieClasspathContainer();
            KieSession kieSession = kieContainer.newKieSession("rulesSession");
            BillItemsBean billItems1 = new BillItemsBean();
            List<BillItemsBean> billItemsBeans = new ArrayList<>();
            kieSession.setGlobal("billret", billItemsBeans);
            kieSession.insert(billItems);
            kieSession.fireAllRules();
            kieSession.dispose();
          //  System.out.println(billItemsBeans.toString());
            logger.info("正常输出-----------------------------------------------------------");
            logger.info(billItemsBeans.toString());
            return billItemsBeans.toString();
        }catch (Exception e){
            String ret="[{\"code\":-1,\"err_message\":"+e.getMessage().toString()+"}]";
            logger.error("异常输出-----------------------------------------------------------");
            logger.error(ret);
            return ret;
        }
    }
}
